package com.cskaoyan.app.service.impl;

import com.cskaoyan.app.bean.po.MarketGoodsExample;
import com.cskaoyan.app.bean.po.MarketGoodsProductExample;
import com.cskaoyan.app.bean.po.MarketOrderExample;
import com.cskaoyan.app.bean.po.MarketUserExample;
import com.cskaoyan.app.bean.vo.DashBoardDataVO;
import com.cskaoyan.app.mapper.MarketGoodsMapper;
import com.cskaoyan.app.mapper.MarketGoodsProductMapper;
import com.cskaoyan.app.mapper.MarketOrderMapper;
import com.cskaoyan.app.mapper.MarketUserMapper;
import com.cskaoyan.app.service.AdminDashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminDashServiceImpl implements AdminDashService {

    @Autowired
    private MarketUserMapper userMapper;

    @Autowired
    private MarketGoodsMapper goodsMapper;

    @Autowired
    private MarketGoodsProductMapper productMapper;

    @Autowired
    private MarketOrderMapper orderMapper;

    @Override
    public DashBoardDataVO getDashData() {
        MarketUserExample userExample = new MarketUserExample();
        userExample.createCriteria().andDeletedEqualTo(false);

        MarketGoodsExample goodsExample = new MarketGoodsExample();
        goodsExample.createCriteria().andDeletedEqualTo(false);

        MarketGoodsProductExample productExample = new MarketGoodsProductExample();
        productExample.createCriteria().andDeletedEqualTo(false);

        MarketOrderExample orderExample = new MarketOrderExample();
        orderExample.createCriteria().andDeletedEqualTo(false);

        long userCount = userMapper.countByExample(userExample);
        long goodsCount = goodsMapper.countByExample(goodsExample);
        long prodCount = productMapper.countByExample(productExample);
        long orderCount = orderMapper.countByExample(orderExample);
        return new DashBoardDataVO(goodsCount, userCount, prodCount, orderCount);
    }
}
